# coding=utf-8
# 全世界最帅的帅哥
from ysgg1_club_oss.nacos_client import client
from ysgg1_club_oss.config.nacos_config import NacosConfig
from ysgg1_club_oss.service.storage_adapter import StorageAdapter
from ysgg1_club_oss.service.impl.minio_storage_adapter import MinioStorageAdapter
from ysgg1_club_oss.service.impl.ali_storage_adapter import AliStorageAdapter
import json


class FileService:

    def __init__(self):
        self._storage_type = json.loads(client.get_config(NacosConfig.DATA_ID, NacosConfig.GROUP)).get(
            "STORAGE_SERVICE_TYPE", "minio")

    def storage_service(self) -> StorageAdapter:
        if self._storage_type == "minio":
            return MinioStorageAdapter
        elif self._storage_type == "aliyun":
            return AliStorageAdapter
        else:
            raise ValueError("未找到对应的文件存储处理器")
